// @Date         2021-12-09
// @Author       Aaron Zhang
// @Description
// @FileName      error_code.go

package api_error

const (
	ErrorCodeSuccess = 1000 + iota
	ErrorCodeDataNotFound
	ErrCodeIntervalServerError

	ErrorCodeEmptyToken
	ErrCodeInvalidToken
	ErrCodeTokenExpire

	ErrCodeParamError
	ErrCodeGetTokenFail
	ErrCodeRecordNotFound
	ErrCodeGeneralCode
	ErrCodeUserOrPwdFail
	ErrCodeGenerateIdFail
)

var codeMsgMap = map[int]string{
	ErrorCodeSuccess:           "success",
	ErrorCodeDataNotFound:      "数据未找到",
	ErrorCodeEmptyToken:        "请求头中auth为空",
	ErrCodeInvalidToken:        "auth格式错误",
	ErrCodeParamError:          "参数错误",
	ErrCodeGetTokenFail:        "获取Token失败",
	ErrCodeRecordNotFound:      "数据库找不到对应资源",
	ErrCodeGeneralCode:         "服务器发生内部错误",
	ErrCodeUserOrPwdFail:       "用户名或密码错误",
	ErrCodeGenerateIdFail:      "生成唯一ID失败",
	ErrCodeTokenExpire:         "Token失效",
	ErrCodeIntervalServerError: "系统内部错误",
}

func getMsg(code int) string {
	if ok := codeMsgMap[code]; ok != "" {
		return ok
	}
	return "未知错误"
}
